package czh.util;

import java.util.*;

/**
 * 空判断工具类
 * @author firr
 * @date 2022年07月08日13:59
 */
public class EmptyUtil {
    /**
     * 判断String为空
     * @author firr
     * @date 2022/7/8 14:15
     * @param str 入参string
     * @return boolean
     */
    public static boolean isEmpty(String str) {
        return str == null || str.trim().isEmpty() || "NULL".equalsIgnoreCase(str);
    }

    /**
     * 判断集合为空
     * @author firr
     * @date 2022/7/8 14:15
     * @param collection 入参集合
     * @return boolean
     */
    public static <E> boolean isEmpty(Collection<E> collection) {
        return collection == null || collection.isEmpty();
    }

    /**
     * 判断Map为空
     * @author firr
     * @date 2022/7/8 14:15
     * @param map 入参map
     * @return boolean
     */
    public static <K,E> boolean isEmpty(Map<K,E> map) {
        return map == null || map.isEmpty();
    }

    /**
     * 判断object为空
     * @author firr
     * @date 2022/7/8 14:16
     * @param o 入参object
     * @return boolean
     */
    public static boolean isEmpty(Object o) {
        return Objects.isNull(o);
    }

    /**
     * 判断String非空
     * @author firr
     * @date 2022/7/8 14:16
     * @param str 入参string
     * @return boolean
     */
    public static boolean isNotEmpty(String str) {
        return !isEmpty(str);
    }

    /**
     * 判断集合非空
     * @author firr
     * @date 2022/7/8 14:17
     * @param collection 入参集合
     * @return boolean
     */
    public static <E> boolean isNotEmpty(Collection<E> collection) {
        return !isEmpty(collection);
    }

    /**
     * 判断map非空
     * @author firr
     * @date 2022/7/8 14:17
     * @param map 入参map
     * @return boolean
     */
    public static <K,E> boolean isNotEmpty(Map<K,E> map) {
        return !isEmpty(map);
    }

    /**
     * 判断object非空
     * @author firr
     * @date 2022/7/8 14:17
     * @param o 入参object
     * @return boolean
     */
    public static boolean isNotEmpty(Object o) {
        return !isEmpty(o);
    }

    public static void main(String[] args) {
        List<Object> list = new ArrayList<>();
        list.add(null);
        System.out.println(EmptyUtil.isEmpty(list));
    }

}
